<template>
	<view class="list">
		<view class="fixbg" :style="{ backgroundImage: `url(${playlist.coverImgUrl})` }"></view>
		<MusicHead :title="playlist.name || '歌单'" :isShowIcon="true" color="white"></MusicHead>
		<view class="container" v-show="!loading">
			<scroll-view scroll-y="true">
				<view class="list-head">
					<view class="list-head-img">
						<image :src="playlist.coverImgUrl" mode=""></image>
						<text class="iconfont iconyousanjiao">{{ playlist.playCount | formatCount }}</text>
					</view>
					<view class="list-head-text">
						<view>{{ playlist.name }}</view>
						<view>
							<image :src="playlist.creator && playlist.creator.avatarUrl" mode=""></image>
							<text>{{playlist.creator && playlist.creator.nickname}}</text>
						</view>
						<view>
							{{ playlist.description }}
						</view>
					</view>
				</view>
				<button class="list-share" open-type="share">
					<text class="iconfont iconicon-"></text>
					分享给微信好友
				</button>
				<view class="list-music">
					<view class="list-music-head">
						<text class="iconfont iconbofang1"></text>
						<text>播放全部</text>
						<text>(共{{ playlist.trackCount }}首)</text>
					</view>
					<view 
						class="list-music-item"
						v-for="item, index in playlist.tracks"
						:key="item.id"
            @tap="handleToDetail(item.id)"
					>
						<view class="list-music-top">{{ index + 1 }}</view>
						<view class="list-music-song">
							<view>{{ item.name }}</view>
							<view>
								<image 
									v-if="privileges[index].flag > 60 && privileges[index].flag < 70" 
									src="../../static/dujia.png" 
									mode=""
								></image>
								<image
									v-if="privileges[index].maxbr === 999000"
									src="../../static/sq.png" 
									mode=""
								></image>
								{{ item.ar[0].name }} - {{ item.name }}
							</view>
						</view>
						<text class="iconfont iconbofang"></text>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import { list } from "@/common/api.js"
	import MusicHead from "@/components/MusicHead.vue"
	export default {
		data() {
			return {
				playlist: {},
				privileges: [],
				loading: false
			}
		},
		components: {
			MusicHead
		},
		onLoad(options) {
			uni.showLoading({
				title: '正在加载...'
			})
			this.getData(options.id)
		},
		methods: {
      handleToDetail(songId) {
        uni.navigateTo({
          url: `/pages/detail/detail?songId=${songId}`,
          
        })
      },
			async getData(id) {
				this.loading = true
				const { data } = await list(id)
				if (data.code === 200) {
					this.playlist = data.playlist
					this.privileges = data.privileges
					this.$store.commit('INIT_TOPLISTIDS', this.playlist.tracks)
				}
				this.loading = false;
				uni.hideLoading()
			}
		}
	}
</script>

<style scoped>
	.list-head {
		display: flex;
		margin: 30rpx;
	}
	
	.list-head-img {
		width: 264rpx;
		height: 264rpx;
		border-radius: 30rpx;
		overflow: hidden;
		position: relative;
		margin-right: 42rpx;
	}
	
	.list-head-img image {
		width: 100%;
		height: 100%;
	}
	
	.list-head-img text {
		position: absolute;
		right: 8rpx;
		top: 8rpx;
		color: white;
		font-size: 26rpx;
	}
	
	.list-head-text {
		flex: 1;
		color: white;
	}
	
	.list-head-text view:nth-child(1) {
		color: white;
		font-size: 34rpx;
	}
	
	.list-head-text view:nth-child(2) {
		margin: 20rpx 0;
		font-size: 26rpx;
		display: flex;
		align-items: center;
	}
	
	.list-head-text view:nth-child(2) image {
		width: 54rpx;
		height: 54rpx;
		border-radius: 50rpx;
		margin-right: 14rpx;
	}
	
	.list-head-text view:nth-child(3) {
		line-height: 32rpx;	
		font-size: 22rpx;
	}
	
	.list-share {
		width: 330rpx;
		height: 74rpx;
		margin: 0 auto;
		background-color: rgba(0, 0, 0, .4);
		border-radius: 37rpx;
		color: white;
		text-align: center;
		line-height: 74rpx;
		font-size: 28rpx;
	}
	.list-share text {
		margin-right: 16rpx;
	}
	
	.list-music {
		background-color: #fff;
		border-radius: 50rpx 50rpx 0 0;
		margin-top: 40rpx;
		padding: 20rpx;
	}
	.list-music-head {
		height: 50rpx;
		margin-bottom: 30rpx;
	}
	
	.list-music-head text:nth-child(1) {
		font-size: 50rpx;
	}
	
	.list-music-head text:nth-child(2) {
		font-size: 32rpx;
		margin: 0 8rpx;
	}
	
	.list-music-head text:nth-child(3) {
		font-size: 20rpx;
		color: #b2b2b2;
	}
	
	.list-music-item {
		display: flex;
		margin-bottom: 33rpx;
		align-items: center;
	}
	
	.list-music-top {
		width: 58rpx;
		color: #959595;
		font-size: 40rpx;
	}
	
	.list-music-song {
		flex: 1;
	}
	
	.list-music-song view:nth-child(1) {
		font-size: 28rpx;
		color: #000;
		width: 70vw;
		white-space: nowrap;
		text-overflow: ellipsis;
	}
	
	.list-music-song view:nth-child(2) {
		display: flex;
		align-items: center;
		gap: 8rpx;
		font-size: 20rpx;
		color: #c1c1c1;
		width: 60vw;
		white-space: nowrap;
		text-overflow: ellipsis;
	}
	
	.list-music-song view:nth-child(2) image {
		width: 32rpx;
		height: 20rpx;
	}
	
	
	.list-music-item text {
		font-size: 50rpx;
		color: #c7c7c7;
	}
</style>
